package edu.sctu.nieyu.day20150617;

import java.io.*;

/**
 * Created by user01 on 2015/6/17.
 */
public class InputStreamUtil {

    public void addFile(File file){
        while (!file.exists()){
            file.mkdir();
        }
    }
    public boolean createNewFile(String filename){
        File file = new File(filename);
       if (!file.exists()){
           try {
               return file.createNewFile();
           } catch (IOException e) {
               e.printStackTrace();
           }
       }
        return false;
    }

    public void getInputStream(){
        File file = new File("D://test2//字节流练习.txt");
        File file1 = new File("D://test//lianxi2.txt");
        int count = 0;
        int countbyte = 0;
        byte[] bytes = new byte[1024];

        FileInputStream fileInputStream ;
        FileOutputStream fileOutputStream;
        try {
            fileInputStream = new FileInputStream(file);
            fileOutputStream = new FileOutputStream(file1);
            try {
                while ((countbyte = fileInputStream.read(bytes))!=-1){
                    count+= countbyte;
                    fileOutputStream.write(bytes,0,countbyte);
                }
                System.out.println(count);
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                fileInputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
}
